<template>
  <header class="header">
    <h1>todos</h1>
    <input
    id="toggle-all"
    class="toggle-all"
    type="checkbox"
    v-model="isAll"
    >
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      @keyup.enter="onAdd"
      v-model.trim="title"
    />
  </header>
</template>

<script>
export default {
  props: ['todos'],
  data () {
    return {
      title: ''
    }
  },
  computed: {
    isAll: {
      get () {
        return this.todos.every(item => item.completed)
      },
      set (val) {
        this.$emit('choice-all', val)
      }
    }
  },
  methods: {
    onAdd () {
      if (this.title === '') {
        return alert('输入为空')
      }
      this.$emit('on-add', this.title)
      this.title = ''
    }
  }
}
</script>
